package thread;


class ThreadTask implements Runnable{
    Object lock1 ;
    Object lock2 ;

    public ThreadTask(Object lock1, Object lock2) {
        this.lock1 = lock1;
        this.lock2 = lock2;
    }

    @Override
    public void run() {
        synchronized (lock1){
            doWork();
            synchronized (lock2){
                doWork();
            }
        }
    }

    private void doWork(){
        System.out.println(Thread.currentThread().getName());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}


public class ThreadLockDemo01 {
    public static void main(String[] args) {



    }

}
